package com.styles.codingstyle.controller;

import com.styles.codingstyle.Security.mapperAndInter.UserServiceForSecurity;
import com.styles.codingstyle.VO.CommonVO;
import com.styles.codingstyle.VO.UserVO;
import com.styles.codingstyle.dataobject.UserEntity;
import com.styles.codingstyle.services.UserService;
import com.styles.codingstyle.utils.CommonVO_Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Package com.styles.codingstyle.controller
 * @Description:
 * @Author 陈建
 * @Create: 2018-05-30 13:16
 * @Version 1.0
 * @Update: message
 */
@RestController
public class UserController {

    @Autowired
    private UserService userServiceImpl;

    @Autowired
    private UserServiceForSecurity userServiceForSecurityImpl;

    @GetMapping(value = "/user/one/{id}")
    public CommonVO getUser(@PathVariable("id") Long id) {
        UserEntity userEntity = userServiceImpl.findById(id);
        return CommonVO_Utils.success(userEntity);
    }

    /**
     * @Description: 注册
     * @Param: []
     * @Return: com.styles.codingstyle.VO.CommonVO
     * @Author: 陈建
     * @date: 2018/6/8 16:38
     */
    @RequestMapping(value = "/register")
    public CommonVO creat(@RequestBody UserEntity userEntity) {
        UserVO userVO = userServiceForSecurityImpl.creatNewUser(userEntity);
        return CommonVO_Utils.success(userVO);
    }

    @RequestMapping(value = "/login")
    public ModelAndView login() {
        ModelAndView view = new ModelAndView();
        view.setViewName("/login");
        return view;
    }

    @GetMapping(value = "/ceshi")
    @Secured(value = {"USER","ADMIN"})
    public ModelAndView ceshi() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/index");
        return modelAndView;
    }
}
